package org.argetr.resim.property;

import java.lang.reflect.InvocationTargetException;

import org.argetr.resim.ui.parts.CellDoubleValidator;
import org.argetr.resim.ui.parts.CellIntegerValidator;
import org.eclipse.jface.viewers.ICellEditorValidator;
import org.eclipse.ui.views.properties.ComboBoxPropertyDescriptor;
import org.eclipse.ui.views.properties.IPropertyDescriptor;

public class ComboBoxPRP extends Property{
	String _values[];
	public ComboBoxPRP(Object owner, String propertyId,
			String displayName, String getterMethod, String setterMethod, String[]values) {
		super(owner, propertyId, displayName, getterMethod, setterMethod);
		_values = values;
		try {
			_setterMethod = _owner.getClass().getMethod(setterMethod,Integer.TYPE);
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		// TODO Auto-generated constructor stub
	}

	@Override
	public Object getValue() {
		try {
			return (Integer)_getterMethod.invoke(_owner);
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public void setValue(Object value) {
		try {
			_setterMethod.invoke(_owner,new Integer(Integer.parseInt(value.toString())));
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	@Override
	public IPropertyDescriptor getDescriptor() {
		ComboBoxPropertyDescriptor lPropDesc = new ComboBoxPropertyDescriptor(_id,_displayName,_values); 
		return lPropDesc;
	}

}
